package team.pwy.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import team.pwy.pojo.entity.Session;

import java.util.List;

@Repository
public interface SessionMapper {
    @Select("select * from pwy.pwy_session where id=#{value}")
    Session findBySessionId(Integer sessionId);

    @Select("select * from pwy.pwy_session where movie_id=#{movieId} and star_time like concat('%',#{time},'%')")
    List<Session> findByMovieId(@Param("movieId") Integer movieId, @Param("time") String time);

    @Update("update pwy.pwy_session set number = number + #{quota} where id = #{id}")
    Integer updateById(@Param("id") Integer id, @Param("quota") Integer quota);

    @Select("select * from pwy.pwy_session where movie_id = #{value} order by star_time desc")
    List<Session> findByMovieIdDesc(Integer movieId);

    // 即将开场,和很久才放映
    @Select("select * from pwy.pwy_session where star_time > DATE_ADD(NOW(),INTERVAL  2 HOUR)")
    List<Session> findStartSessionBefor();

    // 观影历史队列
    @Select("select * from pwy.pwy_session where end_time > NOW()")
    List<Session> findStartSessionEnd();

    // 更新影片上映时间
    @Update("update pwy.pwy_session set star_time = now() , end_time = curdate() + interval 2 day")
    void updateDB();
}
